package com.ctms.system.dao;

import com.ctms.system.domain.RoleDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface RoleMapper {
	@Select("SELECT role_id, role_name,remark, role_sign, gmt_create, gmt_modified ,flag FROM sys_role")
	@Results({ @Result(property = "roleId", column = "role_id"), @Result(property = "roleName", column = "role_name") })
	List<RoleDO> listRole();

	@Insert("INSERT INTO sys_role(role_id, role_name, remark,role_sign, gmt_create, gmt_modified, flag)VALUES(#{roleId}, #{roleName},#{remark}, #{roleSign}, #{gmtCreate}, #{gmtModified},#{flag})")
	@Options(useGeneratedKeys = true,keyProperty="roleId")
	int save(RoleDO role);
	
	@Delete("DELETE FROM sys_role WHERE role_id=#{id}")
	int remove(Long id);
	
	@Select("SELECT role_id, role_name,remark, role_sign,  gmt_create, gmt_modified, flag FROM sys_role where role_id = #{roleId}")
	@Results({ @Result(property = "roleId", column = "role_id"), @Result(property = "roleName", column = "role_name") })
	RoleDO get(Long id);
	
/*	@Update("update sys_role set role_name = #{roleName}  where role_id=#{roleId}")*/
	@Update("<script>"+
		"update sys_role " +
		"<set>" +
		"<if test=\"roleId != null\">`role_id` = #{roleId}, </if>" +
		"<if test=\"remark != null\">`remark` = #{remark}, </if>" +
		"<if test=\"roleName != null\">`role_name` = #{roleName}, </if>" +
		"<if test=\"roleSign != null\">`role_sign` = #{roleSign}, </if>" +
		"<if test=\"gmtCreate != null\">`gmt_create` = #{gmtCreate}, </if>" +
		"<if test=\"gmtModified != null\">`gmt_modified` = #{gmtModified}, </if>" +
		"<if test=\"flag != null\">`flag` = #{flag}, </if>" +
		"</set>" +
		"where role_id=#{roleId}"+
		"</script>")
	int update(RoleDO role);
}
